package sets;


import universe.Discrete;
import universe.IUniverseOfDiscourse;

public class ClassicalSet {

	private IUniverseOfDiscourse universeOfDiscourse;
	
	public void setUniverseOfDiscourse(IUniverseOfDiscourse uod) {
		this.universeOfDiscourse = uod;
	}
	
	public IUniverseOfDiscourse getUniverseOfDiscourse() {
		return universeOfDiscourse;
	}
	
	public Boolean characteristicFunction(double element) {		
		return universeOfDiscourse.isExists(element);
	}
	
	public ClassicalSet union(ClassicalSet set) {
		// Each Universe of Discourse, application should regarded as discrete,
		//	we can do only numerical computational
		
		Discrete universe = new Discrete();
		
		for (Double element : universeOfDiscourse.getElements()) {
			universe.addElement(element);
		}
		
		for (Double element : set.getUniverseOfDiscourse().getElements()) {
			universe.addElement(element);
		}
		
		ClassicalSet newSet = new ClassicalSet();
		newSet.setUniverseOfDiscourse(universe);
		
		return newSet;
	}
	
	public ClassicalSet intersection(ClassicalSet set) {
		Discrete universe = new Discrete();
		
		for (Double element : universeOfDiscourse.getElements()) {
			if (set.getUniverseOfDiscourse().isExists(element)) {
				universe.addElement(element);
			}
		}
		
		ClassicalSet newSet = new ClassicalSet();
		newSet.setUniverseOfDiscourse(universe);
		
		return newSet;
	}
	
	public ClassicalSet complement(ClassicalSet set) {
		Discrete universe = new Discrete();
		
		for (Double element : set.getUniverseOfDiscourse().getElements()) {
			if (!universeOfDiscourse.isExists(element)) {
				universe.addElement(element);
			}
		}
		
		ClassicalSet newSet = new ClassicalSet();
		newSet.setUniverseOfDiscourse(universe);
		
		return newSet;
	}
	
	public void show() {
		for (Double element : universeOfDiscourse.getElements()) {
			System.out.print(element + " ");
		}
		System.out.println("");
	}
}
